package com.ayf.payment.game.api.service.impl;

import com.ayf.payment.game.api.entity.TemplateEscitation;
import com.ayf.payment.game.api.exception.ParameterException;
import com.ayf.payment.game.api.mapper.TemplateEscitationMapper;
import com.ayf.payment.game.api.service.TemplateEscitationService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TemplateEscitationServiceImpl implements TemplateEscitationService {

    @Resource
    private TemplateEscitationMapper templateEscitationMapper;

    @Override
    public boolean insertExcitations(List<TemplateEscitation> escitationList) {
        if (escitationList==null) {
            throw new ParameterException("参数不能为空");
        }
        return templateEscitationMapper.insertExcitations(escitationList)>0;
    }

    @Override
    public List<TemplateEscitation> selectAllByTemplateId(String templateId) {
        TemplateEscitation temp=checkParameter(templateId);
        return templateEscitationMapper.select(temp);
    }

    private TemplateEscitation checkParameter(String templateId) {
        if (StringUtils.isBlank(templateId)) {
            throw new ParameterException("模板id不能为空");
        }
        TemplateEscitation escitation = new TemplateEscitation();
        escitation.setTemplateId(templateId);
        return escitation;
    }

    @Override
    public boolean delEscitationByTemId(String templateId) {
        TemplateEscitation temp=checkParameter(templateId);
        return templateEscitationMapper.delete(temp)>0;
    }
}


